﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bluyel.Core;

namespace Bluyel_Samples_VS10
{
    /// <summary>
    /// Code samples to see how to create:
    /// DVal of phyLength (Physical Quantity Length).
    /// Convertions, comparisons.
    /// </summary>
    public class Sample_DVal_PhyLength
    {
        //---------------------------------------------------------------------
        /// <summary>
        /// Create the type Physical Quantity Length, configure
        /// and define some data values.
        /// </summary>
        public void CreateDValPhyLength()
        {
            Console.WriteLine("\n----Create physical qty length values:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // create a phy qty dval in one instruction: set the value and the prefix: 453 cm (453 centimetre)
            DValPhyLength dvLength453cm = core.DataBuilder.CreateDValPhyLength(453, TypePhyLengthPrefix.Centimetre);
            Console.WriteLine("Create value physical quantity length: " + dvLength453cm.Value + " " + dvLength453cm.Prefix);


            // create a physical qty data value
            DValPhyLength dvLength6m = core.DataBuilder.CreateDValPhyLength();

            // now, set the value and the prefix/multiple: 6 m (6 metres)
            core.DataBuilder.SetVal(dvLength6m, 6, TypePhyLengthPrefix.Metre);
            Console.WriteLine("Create value physical quantity length: " + dvLength6m.Value + " " + dvLength6m.Prefix);

            // now, change the value: 6.2 m (6.2 metres)
            core.DataBuilder.SetVal(dvLength6m, 6.2);
            Console.WriteLine("Change the value from 6 to 6,2: " + dvLength6m.Value + " " + dvLength6m.Prefix);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a dval, convert to another prefix
        /// </summary>
        public void CreateDValPhyLength_ConvertfromPrefixToAnother()
        {
            Console.WriteLine("\n----Convert a physical qty length value from a prefix to another one:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // create a phy qty dval in one instruction: set the value and the prefix: 6 m (6 Metre)
            DValPhyLength dvLength6m = core.DataBuilder.CreateDValPhyLength(6, TypePhyLengthPrefix.Metre);
            Console.WriteLine("Create value physical quantity length: " + dvLength6m.Value + " " + dvLength6m.Prefix);

            // convert the dv in cm: 6m= 600cm 
            DValPhyLength dvLength6mTocm = core.PhQConverter.ConvertTo(dvLength6m, TypePhyLengthPrefix.Centimetre);
            Console.WriteLine("Convert 6 Metre to cm: " + dvLength6mTocm.Value + " " + dvLength6mTocm.Prefix);

            // convert the dv in km: 6m= 0,006km 
            DValPhyLength dvLength6mTokm = core.PhQConverter.ConvertTo(dvLength6m, TypePhyLengthPrefix.Kilometre);
            Console.WriteLine("Convert 6 Metre to km: " + dvLength6mTokm.Value + " " + dvLength6mTokm.Prefix);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create 2 dval, compare.
        /// </summary>
        public void CreateDValPhyLength_Compare()
        {
            Console.WriteLine("\n----Compare 2 physical qty length:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // create a phy qty dval in one instruction: set the value and the prefix: 6 m (6 Metre)
            DValPhyLength dvLength6m = core.DataBuilder.CreateDValPhyLength(6, TypePhyLengthPrefix.Metre);
            Console.WriteLine("Create value physical quantity length: " + dvLength6m.Value + " " + dvLength6m.Prefix);

            // create a phy qty dval in one instruction: set the value and the prefix: 453 cm (453 centimetre)
            DValPhyLength dvLength453cm = core.DataBuilder.CreateDValPhyLength(453, TypePhyLengthPrefix.Centimetre);
            Console.WriteLine("Create value physical quantity length: " + dvLength453cm.Value + " " + dvLength453cm.Prefix);

            // convert the dv in cm: 6m= 600cm 
            DValPhyLength dvLength6mTocm = core.PhQConverter.ConvertTo(dvLength6m, TypePhyLengthPrefix.Centimetre);

            // compare 2 phyLength dval, having differents prefix
            bool res;
            // is 6m > 453cm ? =true
            res = core.PhQConverter.IsGreaterThan(dvLength6m, dvLength453cm);
            Console.WriteLine("is 6m > 453cm ? " + res);

            // is 6m < 453cm ? = false
            res = core.PhQConverter.IsLessThan(dvLength6m, dvLength453cm);
            Console.WriteLine("is 6m < 453cm ? " + res);

            // is 6m == 600cm ? = true
            res = core.PhQConverter.AreEquals(dvLength6m, dvLength6mTocm);
            Console.WriteLine("is 6m == 600cm ? " + res);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create yard/inch unit and convert to SI
        /// </summary>
        public void CreateDValPhyLength_YardAndConvert()
        {
            Console.WriteLine("\n----Create Yard/Inch length and convert to SI:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // create a length data value: 1 m
            DValPhyLength dvLengthOneMetre = core.DataBuilder.CreateDValPhyLength(1, TypePhyLengthPrefix.Metre);
            Console.WriteLine("Create value physical quantity length: " + dvLengthOneMetre.Value + " " + dvLengthOneMetre.Prefix);

            // create a length data value: 1 yard 
            DValPhyLength dvLengthOneYard = core.DataBuilder.CreateDValPhyLength(1, TypePhyLengthPrefix.Yard);
            Console.WriteLine("Create value physical quantity length: " + dvLengthOneYard.Value + " " + dvLengthOneYard.Prefix);

            // convert 1 yard -> m  => 1 yard= 0.9144 metre
            DValPhyLength dvLength1yard_09144m = core.PhQConverter.ConvertTo(dvLengthOneYard, TypePhyLengthPrefix.Metre);
            Console.WriteLine("Convert 1 yard -> m  => 1 yard= " + dvLength1yard_09144m.Value + " " + dvLength1yard_09144m.Prefix);

            // convert 1 m -> yard  => 1 m = 1,0936... yard
            DValPhyLength dvLength1m_1_0936XXYard = core.PhQConverter.ConvertTo(dvLengthOneMetre, TypePhyLengthPrefix.Yard);
            Console.WriteLine("Convert 1 m -> yard  => 1 m = " + dvLength1m_1_0936XXYard.Value + " " + dvLength1m_1_0936XXYard.Prefix);

            // convert 1 yard -> yard  = 1 yard!
            DValPhyLength dvLength1YardRes = core.PhQConverter.ConvertTo(dvLengthOneYard, TypePhyLengthPrefix.Yard);
            Console.WriteLine("1 yard -> yard  = " + dvLength1YardRes.Value + " " + dvLength1YardRes.Prefix);

            // create a length data value: 1 inch 
            DValPhyLength dvLengthOneInch = core.DataBuilder.CreateDValPhyLength(1, TypePhyLengthPrefix.Inch);
            Console.WriteLine("Create value physical quantity length: " + dvLengthOneInch.Value + " " + dvLengthOneInch.Prefix);

            // Convert 1 inch -> m  => 1 inch= 2.54 cm
            DValPhyLength dvLength1yard_2_54cm = core.PhQConverter.ConvertTo(dvLengthOneInch, TypePhyLengthPrefix.Centimetre);
            Console.WriteLine("Convert 1 inch -> cm  => 1 inch= " + dvLength1yard_2_54cm.Value + " " + dvLength1yard_2_54cm.Prefix);
        }

    }
}
